//H routina 1 einai i sunartisi double * vectortoarray(); , kanei return to array pou einai copy tou vector
//H routina 7 einai i sunartisi double * erasenum(); , kanei return to noumero kai tin 8esi tou
//Xrisimopoiw to #include <time.h> kai to #include <assert.h>

#include <iostream>
#include <vector>
#include <time.h>
#include <assert.h>

using namespace std;

class doubleList{
private: 
	vector <double> *dList;

public:
	doubleList() { dList = new vector<double>();}
	~doubleList() { delete dList;}
	double * vectortoarray();
	double * erasenum();
	void insertTo(int,double);
	void printVec();
};


double * doubleList::vectortoarray()
{
	int i;
	double *arrayout = new double[dList->size()];

	for(i=0;i<dList->size();i++)
		arrayout[i]=dList->at(i);

	
	return arrayout;
}

double * doubleList::erasenum()
{
	int pos, oldL;
	double out[2];
	srand(time(NULL));

	oldL=dList->size();

	pos=(rand()%dList->size());
	assert(pos < dList->size());
	assert(pos >= 0);

	out[0]=dList->at(pos);
	out[1]=pos+1;			//position starting from 1

	dList->erase(dList->begin()+pos);
	assert(this->dList->size() == oldL-1);


	return out;
}

void doubleList::insertTo(int pos,double num){

	if ( pos < 0 ) {cout<<"Give positive pos"<<endl; return;}
	if ( pos > this->dList->size()) {cout<<"Out of bounds"<<endl; return;}

	vector<double>::iterator it1 = this->dList->begin();
	for (int i = 0; i < pos; i++) 
		it1++;
	
	this->dList->insert(it1,num);
	
}

void doubleList::printVec(){
	int i;

	for(i=0;i<dList->size();i++)
		cout<<dList->at(i)<<endl;
	
}



int main(){

	double *as;
	double *cu;
	int i;
	doubleList a;
	a.insertTo(0, 5);
	a.insertTo(0, 4);
	a.insertTo(0, 3);
	a.insertTo(0, 2);
	a.insertTo(0, 1);
	printf("Starting Vector:\n");
	a.printVec();
	cu=a.erasenum();
	printf("Number: %f, Position: %f\n", cu[0], cu[1]);
	printf("Updated Vector:\n");
	a.printVec();

	as=a.vectortoarray();
	printf("Array:\n");
	for(i=0;i<4;i++)
		cout<<as[i]<<endl;

	cu=a.erasenum();
	printf("Number: %f, Position: %f\n", cu[0], cu[1]);
	printf("Updated Vector:\n");
	a.printVec();

	cu=a.erasenum();
	printf("Number: %f, Position: %f\n", cu[0], cu[1]);
	printf("Updated Vector:\n");
	a.printVec();

	system("pause");
	return 0;
}